package com.richper.springcloudh2020.service.impl;

import com.richper.springcloudh2020.service.IMProviderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;

import javax.annotation.Resource;
import java.util.UUID;

@EnableBinding(Source.class) //Source 是消息的发送者
@Slf4j
public class IMProviderServiceImpl implements IMProviderService {

    @Resource
    private MessageChannel output; //消息发送管道

    @Override
    public String send() {
        String payload = UUID.randomUUID().toString();
        boolean send = output.send(MessageBuilder.withPayload(payload).build());
        log.info("out send:{},result:{}",payload,send);
        return payload;
    }
}
